﻿/**
 * Peter
 * Created by: Peter Development Team
 *    http://peter.codeplex.com/
 * 
 * GNU General Public License version 2 (GPLv2)
 *    http://peter.codeplex.com/license
 *
 *  This code is provided on an AS IS basis, with no WARRANTIES,
 *  CONDITIONS or GUARANTEES of any kind.
 *  
 **/

using System.Reflection;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Peter.Common.MainMenu;

namespace Peter.Ruby.Tests
{
   /// <summary>
   /// Test cases for the Rails project type.
   /// </summary>
   [TestClass]
   public class RailsProjectTypeTests
   {

      /// <summary>
      /// Tests the properties for the rails project type.
      /// </summary>
      [TestMethod]
      public void TestProperties ()
      {
         var projectType = new RailsProjectType ();
         Assert.AreEqual ("Rails", projectType.Name);
         Assert.AreEqual ("Ruby", projectType.ProjectGroup);
         Assert.AreEqual (MainMenuIcon.Ruby, projectType.Icon);
      }

      /// <summary>
      /// Tests the owns project method.
      /// </summary>
      [TestMethod]
      public void TestOwnsProject ()
      {
         var projectType = new RailsProjectType ();
         Assert.IsTrue (projectType.OwnsProject (typeof(RailsProject).ToString ()));
         Assert.IsFalse (projectType.OwnsProject (typeof (RailsProjectTypeTests).ToString ()));
      }

      /// <summary>
      /// Tests opening a bad project.
      /// </summary>
      [TestMethod]
      public void TestOpenBadProject ()
      {
         var projectType = new RailsProjectType ();
         var project = projectType.Open ("SomeFakePath");
         Assert.IsNull (project);
      }

      /// <summary>
      /// Tests opening an existing project.
      /// </summary>
      [TestMethod]
      public void TestOpenProject ()
      {
         var projectType = new RailsProjectType ();
         var project = projectType.Open (Context.TestDir + "\\TestProject");
         Assert.IsNotNull (project);
      }
      /// <summary>
      /// Gets or Sets the mocked peter project.
      /// </summary>
      protected static MockPeterProject MockProject { get; set; }

      /// <summary>
      /// Gets the test context.
      /// </summary>
      protected static TestContext Context { get; private set; }

      /// <summary>
      /// Initializes the tests in this class.
      /// </summary>
      /// <param name="context">Test context</param>
      [ClassInitialize]
      public static void ClassInitialize (TestContext context)
      {
         Context = context;
         var assem = Assembly.GetExecutingAssembly ();
         MockProject = new MockPeterProject (assem, context.TestDir);
      }

      /// <summary>
      /// Cleans up the tests in this class.
      /// </summary>
      [ClassCleanup]
      public static void ClassCleanup ()
      {
         MockProject.Close (Context.TestDir);
      }
   }
}
